import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { getAllSystemList } from '../group/group.api'
import { getNoticeWayList } from './design.api'

import { render } from '/@/utils/common/renderUtils';


export const columns: BasicColumn[] = [
  {
    title: '爬虫名称',
    dataIndex: 'name',
    width: 180,
    align: 'left',
  },
  {
    title: '归属系统',
    dataIndex: 'systemName',
    width: 120,
    align: 'left',
  },
  {
    title: '周期表达式',
    dataIndex: 'cron',
    slots: { customRender: 'cronLabel' },
    width: 120,
  },
  {
    title: '上次执行时间',
    dataIndex: 'lastExecuteTime',
    width: 120,
  },
  {
    title: '下次执行时间',
    dataIndex: 'nextExecuteTime',
    width: 120,
  },
  {
    title: '运行中/已完成',
    dataIndex: 'runFinish',
    slots: { customRender: 'executeCount' },
    width: 80,
  },
  {
    title: '状态',
    dataIndex: 'enabled',
    width: 80,
    customRender: ({ text }) => {
      const color = text == '1' ? 'green' : text == '0' ? 'red' : 'gray';
      const txt = text == '1' ? '开启' : text == '0' ? '关闭' : '-';
      return render.renderTag(txt, color);
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'systemId',
    label: '所属分组',
    component: 'ApiSelect',
    componentProps: {
      api: getAllSystemList,
      labelField: 'name',
      valueField: 'id',
      showSearch: true,
    },
    colProps: { span: 8 },
  },
  {
    field: 'name',
    label: '爬虫名称',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const noticeTypeOptions = [
  { label: '流程开始', value: 'startNotice' },
  { label: '流程异常', value: 'exceptionNotice' },
  { label: '流程结束', value: 'endNotice' },
];


export const noticeFromSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'recipients',
    label: '收件人',
    component: 'InputTextArea',
    helpMessage:'收件人,多个收件人用","隔开，每个收件人可添加单独通知标记,如不添加通知标记则使用默认配置通知方式。例：sms:13012345678,email:12345678@qq.com,13012345670',
    componentProps: {
      placeholder: '请输入收件人',
      rows: 4,
    },
    required: true,
  },
  {
    field: 'noticeWay',
    label: '通知方式',
    component: 'ApiSelect',
    componentProps: {
      api: getNoticeWayList,
      labelField: 'text',
      valueField: 'value',
      showSearch: true,
      mode: 'multiple',
    },
    required: true,
  },
  {
    field: 'noticeTypes',
    label: '通知类型',
    component: 'CheckboxGroup',
    componentProps: {
      options: noticeTypeOptions,
    },
    required: true,
    //defaultValue: ['exceptionNotice'],
  },
];

export const groupFromSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'systemId',
    label: '所属分组',
    component: 'ApiSelect',
    componentProps: {
      api: getAllSystemList,
      labelField: 'name',
      valueField: 'id',
      showSearch: true,
    },
  },
];